file = open(r"reque.sql", "r")
data = file.read().split('\n')
file.close()

o_table = ''
t_table = ''
sql = ''
for line in data:
    i = line.find("(")
    j = line.find("->")
    k = line.find(")")
    if line[0:3] == '---' and line.find('->') > 0:
        if sql != '':
            f = open(o_table + '.txt', 'w')
            f.write(sql.split(';')[0])
            f.close
            print(o_table + ' -> ' + t_table)
        o_table = line[i + 1:j].strip()
        t_table = line[j + 2:k].strip()
        sql = ''
    else:
        sql = sql + '\n' + line
if sql != '':
    f = open(o_table + '.txt', 'w')
    f.write(sql.split(';')[0])
    f.close
    print(o_table + ' -> ' + t_table)

# ----智慧物流信息(GSP_LOGISTICS_ILS->lg_intelligent_logistics)
# select mam_order_code as order_code,decode(code_type,'BH',0,'RE',1,'TH',2,-1) as refer_type,gsp_code as refer_code,berth_code,berth_name,time_window_s as time_window_start,time_window_e as time_window_end,merge_booking_num,message,
# booking_start_ils,send_zhwl as send_ils,send_sys,merge_flag,license_num,courier_tel,transport_type,identity_card,dr as del_flag,9 as tenant_id,1 as object_version_number
# ,create_time as creation_date,update_time as last_update_date
# from GSP_LOGISTICS_ILS;
# ----送货单收货扫码的物料序列号(GSP_DELIVERY_BARCODE->lg_delivery_barcode)
# select delivery_code,serial_code,vendor_code,material_code,material_name,extend1,extend2,remark,video_second,video_index,qrcode,quantity,draw,9 as tenant_id,1 as object_version_number
# ,create_date as creation_date,creator
# from GSP_DELIVERY_BARCODE
# where CREATE_DATE > TO_DATE('2021-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') ;

# mysql -uroot -p'xxxxxxxx' -D test_db -f < lg_intelligent_logistics.sql > lg_intelligent_logistics.log 2>&1
